package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.MeiTuanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/api/meituan")
public class MeiTuanController {

    @Resource
    private MeiTuanService meiTuanService;

    @GetMapping("/merchant/auth/generalAuthCallbacks")
    public String meituanGeneralAuthCallbacks(HttpServletRequest request) {
        long begin = System.currentTimeMillis();
        String resultMsg = "";
        try {
            //回调请求示例：http://192.168.1.9:8080/device/meituan/merchant/auth/generalAuthCallbacks?code=xxxxx&state=teststate
            resultMsg = meiTuanService.meituanGeneralAuthCallbacks(request);
        } catch (Exception e) {
            resultMsg = "meituanGeneralAuthCallbacks美团商家授权失败";
        } finally {
            long end = System.currentTimeMillis();
            System.out.println("业务花费时间：" + (end - begin) + "毫秒");
        }
        return resultMsg;
    }

    @GetMapping("/merchant/auth/meituanGeneralUnauthCallbacks")
    public String meituanGeneralUnauthCallbacks(HttpServletRequest request) {
        long begin = System.currentTimeMillis();
        String resultMsg = "";
        try {
            //回调请求示例：http://192.168.1.9:8080/device/meituan/merchant/auth/meituanGeneralUnauthCallbacks
            resultMsg = meiTuanService.meituanGeneralUnauthCallbacks(request);
        } catch (Exception e) {
            resultMsg = "meituanGeneralUnauthCallbacks美团商家取消授权失败";
        } finally {
            long end = System.currentTimeMillis();
            System.out.println("业务花费时间：" + (end - begin) + "毫秒");
        }
        return resultMsg;
    }
}
